package com.example.proj_kefei.Controller;

import com.example.proj_kefei.Entity.User;
import com.example.proj_kefei.Service.UserService;
import com.example.proj_kefei.Util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Api("用户管理")
@RestController
@RequestMapping("/User")
public class UserController {

    @Autowired
    UserService userService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        return userService.login(user);
    }

    @ApiOperation("注册")
    @PostMapping("/register")
    public Result register(@RequestBody User user) {
        return userService.register(user);
    }

    @ApiOperation("退出登录")
    @RequestMapping("/exit")
    public Result exit(HttpServletRequest rq) {
        return userService.exit(rq.getHeader("token"));
    }

    @ApiOperation("查找用户信息")
    @GetMapping("/select")
    public Result select() {
        System.out.println("select方法被调用");
        return userService.select();
    }

    @ApiOperation("分页查询")
    @GetMapping("/selectList")
    public Result selectList(User user) {
        return userService.selectList(user);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody User user) {
        return userService.add(user);
    }

    @GetMapping("/delete")
    public Result delete(User user) {
        System.out.println(user.getUserId());
        return userService.delete(user);
    }

    @PostMapping("/update")
    public Result update(@RequestBody User user) {
        return userService.update(user);
    }

}
